/**
 * 
 */
package mediasManagement;

import java.io.Serializable;
import java.util.ArrayList;

import javax.print.attribute.standard.MediaName;

import exceptions.BadParametersException;
import exceptions.MediaExistsException;

/**
 * @author     virgil
 * @uml.dependency   supplier="mediasManagement.FabricCategory"
 * @uml.dependency   supplier="exceptions.MediaExistsException"
 */
public class Category {

	/**
	 * @uml.property  name="name"
	 */
	private String name;

	/**
	 * Getter of the property <tt>name</tt>
	 * @return  Returns the name.
	 * @uml.property  name="name"
	 */
	public String getName() {
		return name;
	}

	/**
	 * Setter of the property <tt>name</tt>
	 * @param name  The name to set.
	 * @uml.property  name="name"
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @uml.property   name="medias"
	 * @uml.associationEnd   multiplicity="(1 -1)" ordering="true" aggregation="shared" inverse="categories:mediasManagement.Media"
	 */
	private ArrayList<String> mediasID = new ArrayList<String>();
	private ArrayList<Media> medias= new ArrayList<Media>();

	/** 
	 * Getter of the property <tt>medias</tt>
	 * @return  Returns the medias.
	 * @uml.property  name="medias"
	 */
	public ArrayList<String> getMedias() {
		return mediasID;
	}

	/** 
	 * Setter of the property <tt>medias</tt>
	 * @param medias  The medias to set.
	 * @uml.property  name="medias"
	 */
	public void setMedias(ArrayList mediasIDs) {
		this.mediasID = mediasID;
	}

	public void addMediaID(Media media)	throws BadParametersException, MediaExistsException {
		if (media == null)
			throw new BadParametersException();

		// Look if the media is already in the library
		if (IsAMediaID(media))
			throw new MediaExistsException();
		this.mediasID.add(media.getMediaNumberId());
	}
	public void addMedia(Media media)	throws BadParametersException, MediaExistsException {
		if (media == null)
			throw new BadParametersException();

		// Look if the media is already in the library
		if (IsAMedia(media))
			throw new MediaExistsException();
		this.medias.add(media);
	}
	
	private boolean IsAMedia(Media media) throws BadParametersException {
		if (media == null)
			throw new BadParametersException();
		
		// If the object is in the list,
		// it is a known media
		return mediasID.contains(media.getMediaNumberId());// TODO Auto-generated method stub
		
	}

	public Boolean IsAMediaID(Media media) throws BadParametersException{
		
		if (media == null)
			throw new BadParametersException();
		
		// If the object is in the list,
		// it is a known media
		return mediasID.contains(media.getMediaNumberId());
	}

	
	/**
	 * create a category of this name
	 * @throws BadParametersException 
	 */
	public Category(String name) throws BadParametersException{
		
		if (name==null)
			throw new BadParametersException();
		this.name=name;
	}	
	public Category(String name,Media media) throws BadParametersException, MediaExistsException{
		
		if (name==null)
			throw new BadParametersException();
		this.name=name;
		this.addMedia(media);
	}	
}
